/* eslint-disable react/jsx-pascal-case */
import React from "react";
import { Fire, FireO } from '@react-vant/icons'
const Comment = () => {
    let navigate = React.$router.useNavigate();
    // 获取路由传参的方法
    let [searchParams] = React.$router.useSearchParams();
    // 获取路由传参的ID值
    const [id, setId] = React.useState(searchParams.get('leaseid'))
    const [LoginUser, setLoginUser] = React.useState(React.$LoginUser ? React.$LoginUser : {})
    const [info, setInfo] = React.useState({
        product: {},
        business: {}
    })
    // 表单信息
    const [form] = React.$Vant.Form.useForm()

    React.useEffect(() => {
        getInfoData()
    }, [])

    const getInfoData = async () => {
        let data = {
            id: id,
            busid: LoginUser.id
        }
        let result = await React.$api.leaseinfo(data)
        if (result && result.code == 1) {
            setInfo(result.data)
        }
    }

    // 拔打客服电话
    const ToContact = () => {
        window.location.href = `tel: ${info.tel}`
    }

    const onFinish = async(values) => {
        console.log(values)
        let data = {
            id: id,
            busid: LoginUser.id,
            rate: values.rate,
            comment: values.comment
        }
        let result = await React.$api.leasecomment(data)
        if(result && result.code == 1){
            React.$Vant.Toast.success({
                message: result.msg,
                onClose: () => {
                    navigate('/business/lease/index')
                }
            })
       } else {
           React.$Vant.Toast.fail({
               message: result.msg
           })
       }
    }


    return (
        <>
            <React.$Vant.NavBar
                fixed
                safeAreaInsetTop
                zIndex="99999"
                title="订单评价"
                onClickLeft={() => navigate('/business/lease/index')}
            />
            <div className="zy_module_content">
                <div className="swiper-container vip_user_order">

                    <div className="swiper-slide">
                        <ul>
                            <li style={{ borderBottom: 'none' }}>
                                <div className="vip_order_goods">
                                    <h3>
                                        <React.$router.NavLink to={`/business/product/info?pid=${info.proid}`}>
                                            <i><img src={info.product.thumbs_text} /></i>
                                            <dl>
                                                <dt>{info.product.name}</dt>
                                                <dd>
                                                    <em>厂家联系人：</em>
                                                    <em>{info.contact}</em>
                                                </dd>
                                                <dd>
                                                    <em>厂家联系电话：</em>
                                                    <em>{info.mobile}</em>
                                                </dd>
                                                <dd>
                                                    <em>归还地址：</em>
                                                    <em>{info.address}</em>
                                                </dd>
                                            </dl>
                                        </React.$router.NavLink>
                                    </h3>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div className="lianxi_ge">
                <div onClick={ToContact}>联系客服</div>
            </div>
            <React.$Vant.Form
                form={form}
                onFinish={onFinish}
                footer={
                    <div style={{ margin: '16px 16px 0' }}>
                        <React.$Vant.Button round nativeType='submit' type='primary' block>
                            提交评论
                        </React.$Vant.Button>
                    </div>
                }
            >
                <React.$Vant.Form.Item
                    rules={[{ required: true, message: '请填写评分' }]}
                    name='rate'
                    label='评分'
                >
                    <React.$Vant.Rate
                        icon={<Fire />}
                        voidIcon={<FireO />}
                    />
                </React.$Vant.Form.Item>
                <React.$Vant.Form.Item
                    rules={[{ required: true, message: '请填写评论' }]}
                    name='comment'
                    label='评论内容'
                >
                    <React.$Vant.Input.TextArea
                        placeholder="请输入评论内容"
                        showWordLimit={({ currentCount }) => <span>已经输入{currentCount}个字啦 ✍️</span>}
                    />
                </React.$Vant.Form.Item>
            </React.$Vant.Form>
        </>
    )
}

export default Comment;